package com.geuso.xingdutch.opposites;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.geuso.xingdutch.R;
import com.geuso.xingdutch.util.SoundUtil;

public class OppositesListAdapter extends ArrayAdapter<Opposite> {

	public OppositesListAdapter(Context context, int resource,
			ArrayList<Opposite> opposites) {
		super(context, resource, opposites);
		
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		View v = convertView;

		// first check to see if the view is null. if so, we have to inflate it.
		// to inflate it basically means to render, or show, the view.
		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.opposites_list_item, null);
		}

		Opposite o = getItem(position);
		if (o != null){
			TextView dutch_word = (TextView) v.findViewById(R.id.opp_ow_dutch);
			TextView dutch_pronounce = (TextView) v.findViewById(R.id.opp_ow_dutch_pronounce);
			TextView english = (TextView) v.findViewById(R.id.opp_ow_english);
			TextView chinese = (TextView) v.findViewById(R.id.opp_ow_chinese);
			ImageView sound_file = (ImageView) v.findViewById(R.id.opp_ow_play_sound) ;

			if (dutch_word != null)		dutch_word.setText(o.getDutch());
			if (dutch_pronounce != null)	dutch_pronounce.setText(o.getDutch_pronounciation());
			if (english != null) 	english.setText(o.getEnglish());
			if (chinese != null) 	chinese.setText(o.getChinese());
			
			if (sound_file != null){
				if ( o.getSoundfile() > 0){
					sound_file.setVisibility(View.VISIBLE);
					SoundUtil.setOnClickPlaySound(sound_file, o.getSoundfile());
				}
				else 	sound_file.setVisibility(View.INVISIBLE);
			}
			
			dutch_word = (TextView) v.findViewById(R.id.opp_oo_dutch);
			dutch_pronounce = (TextView) v.findViewById(R.id.opp_oo_dutch_pronounce);
			english = (TextView) v.findViewById(R.id.opp_oo_english);
			chinese = (TextView) v.findViewById(R.id.opp_oo_chinese);
			sound_file = (ImageView) v.findViewById(R.id.opp_oo_play_sound) ;
			

			if (dutch_word != null) 	dutch_word.setText(o.getOpposite_dutch());
			if (dutch_pronounce != null)	dutch_pronounce.setText(o.getOpposite_dutch_pronounciation());
			if (english != null) 	english.setText(o.getOpposite_english());
			if (chinese != null)	chinese.setText(o.getOpposite_chinese());
			
			if (sound_file != null){
				if ( o.getOpposite_soundfile() > 0)	{
					sound_file.setVisibility(View.VISIBLE);
					SoundUtil.setOnClickPlaySound(sound_file, o.getOpposite_soundfile());
				}
				else 	sound_file.setVisibility(View.INVISIBLE);
			}
			
		}
		return v;
	}
	
	
	
}
	
